package com.cn.yugan.Engine.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cn.yugan.Engine.Holder.SearchHistoryItemHolder;
import com.cn.yugan.mobile.R;
import java.util.List;

/**
 * Created by Rover on 2016/8/10 .
 * Email 357319517@qq.com
 */
public class SearchHistoryListAdapter extends BaseAdapter {

    private Context context;
    private List<String> mlist;
    private LayoutInflater layoutInflater;
    private SearchHistoryItemHolder searchHistoryItemHolder;

    public SearchHistoryListAdapter(Context context,List<String> mlist) {
        this.context = context;
        this.mlist = mlist;
        this.layoutInflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.list_item_searchhistory, null);
            searchHistoryItemHolder = new SearchHistoryItemHolder();
            searchHistoryItemHolder.searchiteminfo = (TextView) convertView.findViewById(R.id.search_history_item_tv);
            searchHistoryItemHolder.searchitemdel = (ImageView) convertView.findViewById(R.id.search_delect_item_iv);
            convertView.setTag(searchHistoryItemHolder);
        } else {
            searchHistoryItemHolder = (SearchHistoryItemHolder) convertView.getTag();
        }
        searchHistoryItemHolder.searchiteminfo.setText(mlist.get(position));
        searchHistoryItemHolder.searchitemdel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (v.getId()==R.id.search_delect_item_iv){
                    //刪除
                    notifyDataSetChanged();
                }
            }
        });
        return convertView;
    }
}
